<?php

namespace App\Http\Controllers\Home;

use App\Http\Controllers\Controller;
use DB;
use Illuminate\Http\Request;
use Crypt;
class enterController extends Controller
{
    public function enter()
    {
        return view('home/enter/enter');
    }
    public function doenter(Request $request)
    {
        $data = $request -> except('_token');

        $res = DB::table('user') -> where('phone', $data['phone']) -> first();


        if(!$res)
        {
            return back() -> with(['info' => '用户名有误']);
        }


        $password = $res -> password;


        $password = Crypt::decrypt($password);


        if($password != $data['password'])
        {
            return back() -> with(['info' => '用户名或密码错误']);
        }


        session(['master' => $res]);
        return redirect('/home/index/index') -> with(['info' => '登录成功']);
    }
    public function num()
    {
        //return 11;
        return view('home.num.num');
    }
    //个人中心的编辑
    public function donum(Request $request)
    {
        // $data = $request -> except('_token');
        //dd($data);
        $newphone = $request -> input('xshouji');
        $passwor = $request -> input('mima');
        $password = Crypt::encrypt($passwor);
        $pic = $request -> input('pic');
        $data = array(
                'phone' => $newphone,
                'password' => $passwor,
                'pic' => $pic
          );
        $res = DB::table('user') -> where('id','=','24') -> update($data);
        // dd($res);
        if($res)
        {

            return view('home.login.login');
        }
    }
}
